var appName = "zbmsg";// 全局服务端入口名
//var doMain = "169.254.226.63";// 域名
var doMain = "127.0.0.1";// 域名
var webHead = "http://"+doMain+"/"+appName+"/"
var prot = ":7397/";// sockt端口
var COOKIE_USER_ID = "_zbmsg_user_id";//cook用户id
var RESPONSE_OK=200;//成功
var RESPONSE_NULL=202;//空
var HEAD_USER_ID="x-request-user-id";//请求头传的userid
var MSG_TYPE_JOINGROUP = "3";
var MSG_TYPE_CREATEGROUP = "4";
var MSG_TYPE_SENDMSG = "6";
/**
 * 进入页面加载
 */
$(document).ready(function() {
	var pn = "";
	pn = window.location.pathname;// 获取页面部分url
	var tn = "/" + appName + "/index.html";
	var key = COOKIE_USER_ID;
	var userId = getCookie(key);
	if (pn != tn) {// 在非登录页状态下,cookie不存在强制调转到登录页
		if (userId == "") {
			window.location.href = "/" + appName + "/index.html";
		} else if (userId != "" && pn == tn) {
			// 新增逻辑:如果存在cookie并且当前在登录页则跳转到房间首页
			window.location.href = "/" + appName + "/html/chat/chatlist.html";
		}
	} else if (userId != "") {
		// 新增逻辑:如果存在cookie并且当前在登录页则跳转到房间首页
		window.location.href = "/" + appName + "/html/chat/chatlist.html";
	}

});

/**
 * 设置cookie
 */
function setCookie(c_name, value, expiredays)// 时间可以直接设置null
{
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value)
			+ ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
			+ "; path=/";
}
/**
 * 获取cookie
 */
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1
			c_end = document.cookie.indexOf(";", c_start)
			if (c_end == -1)
				c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		}
	}
	return ""
}

/**
 * 获取网页传递的参数
 */
function requestParam(paras) {
	url = location.href;
	var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
	var paraObj = {}
	for (i = 0; j = paraString[i]; i++) {
		paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j
				.indexOf("=") + 1, j.length);
	}
	var returnValue = paraObj[paras.toLowerCase()];
	if (typeof (returnValue) == "undefined") {
		return "";
	} else {
		return returnValue;
	}
}